#include "mainwindow.h"
#include "ui_mainwindow.h"
//
#include <QFile>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //
    edit=new QLineEdit(this);
    edit->setGeometry(QRect(50,50,200,25));
    edit->setText("C:/text.txt");
    content=new QLineEdit(this);
    content->setGeometry(QRect(50,100,200,25));
    content->setText(QString::fromUtf8( "aaa"));
    button=new QPushButton(this);
    button->setGeometry(QRect(270,50,80,25));
    button->setText("创建");
    connect(button,SIGNAL(clicked(bool)),this,
            SLOT(createFile())
            );

}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::createFile()
{
    QFile file(edit->text());
    if(file.exists())
    {
        QMessageBox::warning(this,"Create File","Has been Created!");
    }else
    {
        file.open(QIODevice::ReadWrite|QIODevice::Text);
        QByteArray str=content->text().toUtf8();
        file.write(str);
        QMessageBox::warning(this,"Create file","Has been created!");

    }
    file.close();
}
